package com.wenjiang.service;

import com.wenjiang.dao.userdao;
import com.wenjiang.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;
import java.util.UUID;

@Service
@Transactional //控制事务
public class userserviceimpl implements userservice {
    @Autowired
    private userdao userdao;


    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findall() {
        return userdao.findall();
    }

    @Override
    public void saveuser(User user) {
        user.setId(UUID.randomUUID().toString());
        userdao.saveuser(user);
    }

    @Override
    public void deleteuser(String id) {
        userdao.delete(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public User findbyid(String id) {
        return userdao.findbyid(id);
    }

    @Override
    public void updateuser(User user) {
        userdao.updateuser(user);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> finanameorphone(String name, String code) {
       return  userdao.findnameorphonenumber(name,code);
    }
}
